package nc.ui.medpub.bd.hf00101010;

import java.awt.Container;
import java.util.Collection;

import nc.bs.framework.common.NCLocator;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.ui.pub.ClientEnvironment;
import nc.ui.trade.bsdelegate.BDBusinessDelegator;
import nc.vo.medpub.bd.hf00101010.MedOrgManVO;
import nc.vo.pub.SuperVO;

public class ClientBusinessDelegator extends BDBusinessDelegator {

	private Container parent;
	private String areaId;
	private String versionId;
	
	public ClientBusinessDelegator(Container parent) {
		super();
		this.parent = parent;
	}
	
	
	@Override
	public SuperVO[] queryHeadAllData(Class headClass, String strBillType,
			String strWhere) throws Exception {
		
		StringBuffer where = new StringBuffer("select t.*, ");
		where.append(" (case t.npointorg_type");
		where.append(" when 0 then (select dd.qzsm from med_dd dd where dd.bname='med_medorgman' and dd.zdname ='orgtype_b' and dd.xh = t.npointorg_type_b)");
		where.append(" when 1 then (select dd.qzsm from med_dd dd where dd.bname='med_medorgman' and dd.zdname ='orgtype_b_sale' and dd.xh = t.npointorg_type_b)");
		where.append(" end) as npointorg_type_b_list");
		where.append(" from med_medorgman t ");
		where.append("left join bd_cubasdoc bas on bas.pk_cubasdoc = t.ccubasid");
		where.append(" where bas.pk_areacl='"+getAreaId()+"' ");
		if(null != getVersionId() && getVersionId().trim().length() >0){
			where.append(" and t.pk_pointmedorgdef = '"+getVersionId()+"'");
		}
		where.append(" and isnull(t.dr,0)=0 " );
		where.append(" and isnull(bas.dr,0)=0 ");
		where.append(" and t.pk_corp='"+ClientEnvironment.getInstance().getCorporation().getPrimaryKey()+"'");
		IUAPQueryBS  bs = NCLocator.getInstance().lookup(IUAPQueryBS .class);
		Collection<MedOrgManVO> coll = (Collection<MedOrgManVO>)bs.executeQuery(where.toString(), new BeanListProcessor(MedOrgManVO.class));
		SuperVO[] vo = null;
		if(null != coll && coll.size()>0){
			vo = (SuperVO[])coll.toArray(new MedOrgManVO[0]);
		}
		return vo;
	}


	public String getAreaId() {
		return areaId;
	}


	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}
  

	public String getVersionId() {
		return versionId;
	}


	public void setVersionId(String versionId) {
		this.versionId = versionId;
	}
}
